<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //原数组
        var arr1 = [33, 44, 11, 22, [77, 88],
            [11, 999]
        ];
        //结果数组  "每一个都有一个结果"
        var result = [];
        //函数  这个 函数会被递归

        function deepClone(arr) {
            //遍历数组的每一项
            for (var i = 0; i < arr.length; i++) {
                //类型判断 如果遍历到的项是数组
                if (Array.isArray(arr[i])) {
                    //递归
                    result.push(deepClone(arr[i]));
                } else {
                    //如果遍历到的项不是数组，是基本类型，就直接推入到结果数组中
                    //相当于是递归的出口
                    result.push(arr[i])

                }
            }
            //返回结果数组
            return result;

        }
        //测试一下
        var arr2 = deepClone(arr1);
        console.log(arr2);

        //是否藕断丝连
        console.log(arr1[4] == arr2[4]);
        arr1[4].push(99);
        console.log(arr1)
        console.log(arr2);
    </script>
</body>

</html>